﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightBase
{
	public class Comments
	{
		/*

		public class Events
		{
			public static void CommentAdd_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
			{
				string error = "";

				if (((TextBox)((Page)Application.Current.RootVisual).ContentGrid.FindName("CommentAddName")).Text.Length < 2)
					error = "Name not valid.";

				if (!Stuff.IsEmail(((TextBox)((Page)Application.Current.RootVisual).ContentGrid.FindName("CommentAddEmail")).Text))
					error = "Email is not valid.";

				if (error == "")
				{
					System.Net.HttpWebRequest httpRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(new Uri("http://" + Application.Current.Host.Source.Host + "/data/blog/post-comment.aspx", UriKind.Absolute));

					httpRequest.ContentType = "application/x-www-form-urlencoded";
					httpRequest.Method = "POST";

					httpRequest.BeginGetRequestStream(new AsyncCallback(ContinueGettingResponse), httpRequest);

					((TextBlock)((Page)Application.Current.RootVisual).ContentGrid.FindName("CommentHeadline")).Text = "Add comment: Thank you for posting.";
				}
				else
				{
					((TextBlock)((Page)Application.Current.RootVisual).ContentGrid.FindName("CommentHeadline")).Text = error;
				}
			}

			public static void ContinueGettingResponse(IAsyncResult asyncRes)
			{
				Application.Current.RootVisual.Dispatcher.BeginInvoke(delegate()
				{
					// Continue getting response
					System.Net.HttpWebRequest httpRequest = (System.Net.HttpWebRequest)asyncRes.AsyncState;

					System.IO.StreamWriter postdateWriter = new System.IO.StreamWriter(httpRequest.EndGetRequestStream(asyncRes), System.Text.Encoding.UTF8);

					postdateWriter.Write(((Page)Application.Current.RootVisual).currentNodeId.ToString() + "$$$$$");
					postdateWriter.Write(((TextBox)((Page)Application.Current.RootVisual).ContentGrid.FindName("CommentAddName")).Text + "$$$$$");
					postdateWriter.Write(((TextBox)((Page)Application.Current.RootVisual).ContentGrid.FindName("CommentAddEmail")).Text + "$$$$$");
					postdateWriter.Write(((TextBox)((Page)Application.Current.RootVisual).ContentGrid.FindName("CommentAddHeadline")).Text + "$$$$$");
					postdateWriter.Write(((TextBox)((Page)Application.Current.RootVisual).ContentGrid.FindName("CommentAddComment")).Text);

					postdateWriter.Close();

					httpRequest.BeginGetResponse(new AsyncCallback(RetriveResponseAsync), httpRequest);
				});

			}

			public static void RetriveResponseAsync(IAsyncResult asyncRes)
			{
				System.Net.HttpWebRequest httpRequest = (System.Net.HttpWebRequest)asyncRes.AsyncState;
				System.Net.HttpWebResponse httpResponse = (System.Net.HttpWebResponse)httpRequest.EndGetResponse(asyncRes);

				WebClient clientSiteXml = new WebClient();
				clientSiteXml.DownloadStringCompleted += new DownloadStringCompletedEventHandler(((Page)Application.Current.RootVisual).clientSiteXml_Completed);
				clientSiteXml.DownloadStringAsync(new Uri(((Page)Application.Current.RootVisual).siteBasPath + "/xml.aspx?random" + DateTime.Now.ToString("hh:mm:ss"), UriKind.RelativeOrAbsolute));
			}

			public static void CommentDisplayHide_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
			{
				double oldHeight = ((Grid)((Grid)sender).Parent).ActualHeight;
				double newHeight = 0;

				RotateTransform rt = new RotateTransform();
				rt.CenterX = 20;
				rt.CenterY = 20;

				if (((TextBlock)((Page)Application.Current.RootVisual).CommentGrid.FindName("CommentText" + ((Grid)sender).Tag)).Visibility == Visibility.Collapsed)
				{
					rt.Angle = 90;
					((Grid)sender).RenderTransform = rt;
					((TextBlock)((Page)Application.Current.RootVisual).CommentGrid.FindName("CommentText" + ((Grid)sender).Tag)).Visibility = Visibility.Visible;
				}
				else
				{
					rt.Angle = 0;
					((Grid)sender).RenderTransform = rt;
					((TextBlock)((Page)Application.Current.RootVisual).CommentGrid.FindName("CommentText" + ((Grid)sender).Tag)).Visibility = Visibility.Collapsed;
				}

				((Grid)((Grid)sender).Parent).UpdateLayout();

				newHeight = ((Grid)((Grid)sender).Parent).ActualHeight;

				bool hasFoundToogleItem = false;

				foreach (Grid g in ((Page)Application.Current.RootVisual).CommentGrid.Children)
				{
					if (hasFoundToogleItem)
					{
						g.Margin = new Thickness(142, g.Margin.Top + (newHeight - oldHeight), 0, 0);
					}

					if (g.Name == ((Grid)((Grid)sender).Parent).Name)
						hasFoundToogleItem = true;
				}
			}
		}
		 */
	}
}
